<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			/* 
				实现对数组的深度克隆
			 */
			/* 
				思路:
					操作对象是 数组
					实现的操作是 深度克隆，分 克隆 和 深度
			 */
			/* 
				将复杂类型解构成简单类型，再进行赋值操作
			 */
			function deep(obj){
				var newObj;
				if(typeof obj == 'object' && obj !== null){
					
					if(obj instanceof Array){
						newObj = [];
					}else{
						newObj = {};
					}
					for(key in obj){
						newObj[key] = deep(obj[key]);
					}
				}else{
					newObj = obj;
				}
				return newObj;
			}
			
			var data1 = {
				sub1: {
					name: 1,
					age: 12
				},
				sub2: [3,4],
				sub3: [5,6]
			}
			
			var data2 = deep(data1);
			
			console.log(data2, data2 === data1);
			
			// json字符串
			var data3 = JSON.stringify(data1);
			data3 = JSON.parse(data3);
		</script>
	</body>
</html>
